
def checker(board, word, last_idx = nil)
  return true if word.empty?
  #take letter from front of word
  letter = word.slice!(0)
  this_idx = []

  # change last letter to "NO"
  if last_idx
    board[last_idx[:row]][last_idx[:column]] = "NO"
  end

  # check board for letter
  board.each_with_index do |row, idx|
    # if this letter is included
    row.each_with_index do |item, idx2|
      if item == letter
        this_idx << { row: idx, column: idx2 }
      end
    end
  end

  draw board

  # if the letter was included
  if this_idx.any?
    this_idx.each do |idx|
      # if this letter is less than one space away from last
      if last_idx == nil || ((last_idx[:row] - idx[:row]).abs <= 1 &&
                                    (last_idx[:column] - idx[:column]).abs <= 1)
        # call this method RECURSIVELY
        # return is needed, WHY??
        return checker(board, word, idx)
      else
        return false
      end
    end
  # if the letter was not included
  else
    return false
  end
end

def draw(thing)
  thing.each { |item| p item }
end

boardy = [%w(w a k e), %w(q b g m), %w(d e n t), %w(f l o p)]

draw(boardy)
# p checker(boardy, "emnldb")
p checker(boardy, "eqag")
